package view;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Insets;
import java.util.ArrayList;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import main.Game;
import controler.ChoiceListener;

public class Choice_view extends JFrame{
	Game game;
	Font font = new Font("Arial",Font.BOLD,14);
	Integer [] items = {2,3,4,5,6};
	
	ImageIcon boat = new ImageIcon(new ImageIcon("img/boat.png").getImage().getScaledInstance(30, 40, Image.SCALE_DEFAULT));
	ImageIcon bourse = new ImageIcon(new ImageIcon("img/bourse.png").getImage().getScaledInstance(30, 30, Image.SCALE_DEFAULT));
	ImageIcon car = new ImageIcon(new ImageIcon("img/car.png").getImage().getScaledInstance(40, 30, Image.SCALE_DEFAULT));
	ImageIcon canon = new ImageIcon(new ImageIcon("img/canon.png").getImage().getScaledInstance(35, 40, Image.SCALE_DEFAULT));
	ImageIcon hat = new ImageIcon(new ImageIcon("img/hat.png").getImage().getScaledInstance(30, 30, Image.SCALE_DEFAULT));
	ImageIcon barrow = new ImageIcon(new ImageIcon("img/barrow.png").getImage().getScaledInstance(35, 30, Image.SCALE_DEFAULT));
	ImageIcon dog = new ImageIcon(new ImageIcon("img/dog.png").getImage().getScaledInstance(40, 40, Image.SCALE_DEFAULT));
	ImageIcon shoe = new ImageIcon(new ImageIcon("img/shoe.png").getImage().getScaledInstance(30, 40, Image.SCALE_DEFAULT));
	ImageIcon knight = new ImageIcon(new ImageIcon("img/knight.png").getImage().getScaledInstance(30, 40, Image.SCALE_DEFAULT));
	ImageIcon iron = new ImageIcon(new ImageIcon("img/iron.png").getImage().getScaledInstance(40, 40, Image.SCALE_DEFAULT));
	ImageIcon thimble = new ImageIcon(new ImageIcon("img/thimble.png").getImage().getScaledInstance(30, 35, Image.SCALE_DEFAULT));
	
	public JComboBox<Integer>nbCombox;
	public ImageIcon [] items2 = {car,shoe,thimble,dog,hat,barrow,bourse,knight,canon,boat,iron};
	public JCheckBox bot2,bot3,bot4,bot5,bot6;
	public JTextField nameTextField1,nameTextField2,nameTextField3,nameTextField4,nameTextField5,nameTextField6;
	public JComboBox pawn_choice1,pawn_choice2,pawn_choice3,pawn_choice4,pawn_choice5,pawn_choice6;
	public ArrayList<JComboBox> pawnList;
	public ArrayList<JTextField>nameList;
	
	public Choice_view (Game g){
		this.game=g;
		JPanel fen= new JPanel();
		fen.setLayout(new BoxLayout(fen, BoxLayout.Y_AXIS));
		JPanel choiNb = new JPanel();
		JPanel formulaire = new JPanel(new GridBagLayout());
		//JPanel formulaire = new JPanel(new GridLayout(7,3,10,30));
		GridBagConstraints gbc = new GridBagConstraints();
		JLabel titre = new JLabel("Nouveaux Joueurs");
		titre.setFont(font);
		titre.setAlignmentX(CENTER_ALIGNMENT);
		JLabel nbPlayer = new JLabel("Nombre de joueurs : ");
		nbCombox = new JComboBox<Integer>(items);
		nbCombox.addActionListener(new ChoiceListener(game, this));
		
		JLabel playerName = new JLabel("Name");
		playerName.setHorizontalAlignment((int) playerName.CENTER_ALIGNMENT);
		JLabel pawnLabel = new JLabel("Pawn");
		pawnLabel.setHorizontalAlignment((int) pawnLabel.CENTER_ALIGNMENT);
		JLabel iaLabel = new JLabel("Bot"); 
		iaLabel.setHorizontalAlignment((int) iaLabel.CENTER_ALIGNMENT);
		JLabel vide = new JLabel();
		vide.setMaximumSize(new Dimension(0,0));
		
		bot2 = new JCheckBox();
		bot3 = new JCheckBox();
		bot3.setVisible(false);
		bot4 = new JCheckBox();
		bot4.setVisible(false);
		bot5 = new JCheckBox();
		bot5.setVisible(false);
		bot6 = new JCheckBox();
		bot6.setVisible(false);
		
		Font font = new Font("arial",Font.BOLD, 16);
		
		nameTextField1= new JTextField(15);
		nameTextField1.setFont(font);
		nameTextField2= new JTextField(15);
		nameTextField2.setFont(font);
		nameTextField3= new JTextField(15);
		nameTextField3.setFont(font);
		nameTextField3.setVisible(false);
		nameTextField4= new JTextField(15);
		nameTextField4.setFont(font);
		nameTextField4.setVisible(false);
		nameTextField5= new JTextField(15);
		nameTextField5.setFont(font);
		nameTextField5.setVisible(false);
		nameTextField6= new JTextField(15);
		nameTextField6.setFont(font);
		nameTextField6.setVisible(false);
		
		pawn_choice1 = new JComboBox<>(items2);
		pawn_choice2 = new JComboBox<>(items2);
		pawn_choice3 = new JComboBox<>(items2);
		pawn_choice3.setVisible(false);
		pawn_choice4 = new JComboBox<>(items2);
		pawn_choice4.setVisible(false);
		pawn_choice5 = new JComboBox<>(items2);
		pawn_choice5.setVisible(false);
		pawn_choice6 = new JComboBox<>(items2);
		pawn_choice6.setVisible(false);
		
		choiNb.add(nbPlayer);
		choiNb.add(nbCombox);
		nameTextField1.setPreferredSize(new Dimension(50,24));
		gbc.insets = new Insets(10, 10, 10, 10);
		gbc.gridy=0;gbc.gridx=0;
		formulaire.add(playerName,gbc);gbc.gridx=1;formulaire.add(pawnLabel,gbc);gbc.gridx=2;formulaire.add(iaLabel,gbc);
		gbc.gridy=1;gbc.gridx=0;
		formulaire.add(nameTextField1,gbc);gbc.gridx=1;formulaire.add(pawn_choice1,gbc);//gbc.gridy=2;formulaire.add(vide,gbc);
		gbc.gridy=2;gbc.gridx=0;
		formulaire.add(nameTextField2,gbc);gbc.gridx=1;formulaire.add(pawn_choice2,gbc);gbc.gridx=2;formulaire.add(bot2,gbc);
		gbc.gridy=3;gbc.gridx=0;
		formulaire.add(nameTextField3,gbc);gbc.gridx=1;formulaire.add(pawn_choice3,gbc);gbc.gridx=2;formulaire.add(bot3,gbc);
		gbc.gridy=4;gbc.gridx=0;
		formulaire.add(nameTextField4,gbc);gbc.gridx=1;formulaire.add(pawn_choice4,gbc);gbc.gridx=2;formulaire.add(bot4,gbc);
		gbc.gridy=5;gbc.gridx=0;
		formulaire.add(nameTextField5,gbc);gbc.gridx=1;formulaire.add(pawn_choice5,gbc);gbc.gridx=2;formulaire.add(bot5,gbc);
		gbc.gridy=6;gbc.gridx=0;
		formulaire.add(nameTextField6,gbc);gbc.gridx=1;formulaire.add(pawn_choice6,gbc);gbc.gridx=2;formulaire.add(bot6,gbc);
		
		JButton valid = new JButton("Validate");
		valid.addActionListener(new ChoiceListener(game,this));
		fen.add(titre);
		fen.add(Box.createVerticalGlue());
		fen.add(choiNb);
		fen.add(Box.createVerticalGlue());
		fen.add(formulaire);
		fen.add(Box.createVerticalGlue());
		fen.add(valid);
		fen.add(Box.createVerticalGlue());
		this.setContentPane(fen);
		this.setTitle("Board");//Title of the Frame
		this.setSize(500,620);//size of the Frame
		//this.setExtendedState(JFrame.MAXIMIZED_BOTH);
		this.setLocationRelativeTo(null);//center the frame
		this.setVisible(true);//Set the frame visible
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
	}

}
